home *** CD-ROM | disk | FTP | other *** search
/ Champak 66 / Vol 66.iso / games / bluep.swf / scripts / __Packages / Enemy.as < prev    next >
Encoding:
Text File  |  2013-04-24  |  3.4 KB  |  105 lines

  1. class Enemy extends MovieClip
  2. {
  3.    var _damage;
  4.    var _life;
  5.    var _holdMovement;
  6.    var enemyIncrem2;
  7.    var enemySetBase2;
  8.    var _dead;
  9.    function Enemy()
  10.    {
  11.       super();
  12.       this._damage = 1;
  13.       this._life = 2;
  14.       this._holdMovement = true;
  15.       this.enemyIncrem2 = 0;
  16.       this.enemySetBase2 = _global.FPSforTweenClass * 1;
  17.       this._dead = false;
  18.    }
  19.    function onEnterFrame()
  20.    {
  21.       this.rotateEnemy();
  22.       this.enemyShoot();
  23.       this.enemyDie();
  24.    }
  25.    function enemyDie()
  26.    {
  27.       var i = 0;
  28.       while(i < _root.arrBullets.length)
  29.       {
  30.          var ObjRef = eval("_root." + _root.arrBullets[i]);
  31.          if(this.hitTest(ObjRef._x,ObjRef._y))
  32.          {
  33.             if(!ObjRef._enemy)
  34.             {
  35.                var rotRan = 1 + Math.floor(Math.random() * 360);
  36.                if(this._life >= 1)
  37.                {
  38.                   var hitAnName = "shield_hits" + _root.getNextHighestDepth();
  39.                   _root.attachMovie("shield_hits",hitAnName,_root.getNextHighestDepth());
  40.                   _root[hitAnName]._x = ObjRef._x;
  41.                   _root[hitAnName]._y = ObjRef._y;
  42.                   _root[hitAnName]._rotation = rotRan;
  43.                }
  44.                if(this._life > 0)
  45.                {
  46.                   _root.removeCallback(_root.arrBullets[i]);
  47.                   _root[_root.arrBullets[i]].removeMovieClip();
  48.                   _root.arrBullets.splice(i,1);
  49.                   this._life--;
  50.                }
  51.                else
  52.                {
  53.                   this._dead = true;
  54.                   _root.removeCallback(_root.arrBullets[i]);
  55.                   _root[_root.arrBullets[i]].removeMovieClip();
  56.                   _root.arrBullets.splice(i,1);
  57.                   var deathAnimationName = "death_" + _root.getNextHighestDepth();
  58.                   _root.enemyLayer.attachMovie("enemy_1_death",deathAnimationName,_root.getNextHighestDepth());
  59.                   _root.enemyLayer[deathAnimationName]._x = this._x;
  60.                   _root.enemyLayer[deathAnimationName]._y = this._y;
  61.                   _root.enemyLayer[deathAnimationName]._rotation = rotRan;
  62.                   _root.ReportEnemyDeath(this._name);
  63.                   this.removeMovieClip();
  64.                }
  65.             }
  66.          }
  67.          i++;
  68.       }
  69.    }
  70.    function dieNow()
  71.    {
  72.       trace("die now called");
  73.       _root.killAllAnimations(this._x,this._y);
  74.       this.removeMovieClip();
  75.    }
  76.    function rotateEnemy()
  77.    {
  78.       if(!this._dead)
  79.       {
  80.          var _loc3_ = new Vector();
  81.          _loc3_._x = _root.pointer._x - this._x - _root.enemyLayer._x;
  82.          _loc3_._y = _root.pointer._y - this._y - _root.enemyLayer._y;
  83.          var _loc4_ = Math.atan2(_loc3_._y,_loc3_._x);
  84.          var _loc5_ = 360 * _loc4_ / 6.283185307179586;
  85.          this._rotation = _loc5_;
  86.       }
  87.       else
  88.       {
  89.          this._rotation = this._rotation;
  90.       }
  91.    }
  92.    function enemyShoot()
  93.    {
  94.       if(this.enemyIncrem2 >= this.enemySetBase2)
  95.       {
  96.          var _loc3_ = new Vector();
  97.          _loc3_._x = Math.cos(3.141592653589793 * this._rotation / 180) * 7;
  98.          _loc3_._y = Math.sin(3.141592653589793 * this._rotation / 180) * 7;
  99.          _root.shootEnemyGun(_loc3_._x,_loc3_._y,this._x + _root.arena._x,this._y + _root.arena._y);
  100.          this.enemyIncrem2 = 0;
  101.       }
  102.       this.enemyIncrem2 = this.enemyIncrem2 + 1;
  103.    }
  104. }
  105.